﻿using System;

using System.Collections.Generic;
using System.Text;
using System.Drawing;
using Silvermoon.Utils;

namespace Silvermoon.Animations
{

    public class ColorAnimation : Animation<Color>
    {
        private int a0, r0, g0, b0;
        private int a1, r1, g1, b1;

        protected override void Prepare()
        {
            a0 = From.A;
            r0 = From.R;
            g0 = From.G;
            b0 = From.B;

            a1 = To.A;
            r1 = To.R;
            g1 = To.G;
            b1 = To.B;
        }

        protected override Color CalculateValue(float value)
        {
            int a = interpolate(a0, a1, value);
            int b = interpolate(b0, b1, value);
            int r = interpolate(r0, r1, value);
            int g = interpolate(g0, g1, value);
            return ColorUtil.FromArgb(a, r, g, b);               
        }

        private int interpolate(int v0, int v1, float value)
        {
            return (int)((v1 - v0) * value) + v0;
        }
    }
}
